package com.link.base.core.basic.util.datax;

import java.util.ArrayList;
import java.util.List;

/**
 * Just Battle 小程序
 * @author 何启谦
 * @date 2019/4/26
 */
public class JustBattle {

    /**
     * 产品
     */
    public static String prodTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        //临时表名称
        String tempTableName = "jb_show";
        //正式表名称
        String targetTableName = "lnk_prod";
        //填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();
        fieldList.add(new FieldMapping("id", "prod_code", "VARCHAR(100)"));
        fieldList.add(new FieldMapping("name", "prod_name", "VARCHAR(200)"));
        fieldList.add(new FieldMapping("ticket_price", "price", "DECIMAL(22,7)"));
        fieldList.add(new FieldMapping("(case when t1.status = '0' then 'N' else 'Y' end)", "is_effective", "CHAR(1)"));
        fieldList.add(new FieldMapping("'wxe3348b3067b4de28'", "prod_good_type", "VARCHAR(50)"));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName,
                fieldList, "prod_good_type");
    }

    /**
     * 订单头
     */
    public static String orderTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        //临时表名称
        String tempTableName = "jb_order";
        //正式表名称
        String targetTableName = "lnk_sale_order";
        //填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();
        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_accnt s1 "
                + "where s1.ACCT_CHANNEL = 'wxe3348b3067b4de28' and s1.integration_id = t1.user_id limit 1)",
                "acct_id", "varchar(50)").setRequired(true));
        fieldList.add(new FieldMapping("sn", "order_no", "VARCHAR(100)"));
        fieldList.add(new FieldMapping("order_amount", "ord_amount", "DECIMAL(22,7)"));
        fieldList.add(new FieldMapping("order_time", "order_date", "DATETIME"));
        fieldList.add(new FieldMapping("'wxe3348b3067b4de28'", "source_from", "VARCHAR(50)"));
        fieldList.add(new FieldMapping("'SalesOrder'", "order_type", "VARCHAR(100)"));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName,
                fieldList, "source_from");
    }

    /**
     * 订单行
     */
    public static String orderItemTemp() {
        //临时表主键名称
        String tempTablePrimaryKeyFieldName = "id";
        //临时表名称
        String tempTableName = "jb_order_product";
        //正式表名称
        String targetTableName = "lnk_sale_order_item";
        //填充字段信息
        List<FieldMapping> fieldList = new ArrayList<>();
        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_sale_order s1 where "
                + " s1.source_from = 'wxe3348b3067b4de28' and s1.integration_id = t1.order_id limit 1)",
                "head_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("(select s1.row_id from linkcrm.lnk_prod s1 "
                + "where s1.prod_good_type = 'wxe3348b3067b4de28' and s1.integration_id = t1.show_id limit 1)",
                "prod_id", "varchar(50)").setRequired(true));

        fieldList.add(new FieldMapping("price", "base_pri", "DECIMAL(22,7)"));
        fieldList.add(new FieldMapping("number", "prod_num", "DECIMAL(22,7)"));
        fieldList.add(new FieldMapping("'wxe3348b3067b4de28'", "order_source", "varchar(50)"));
        fieldList.add(new FieldMapping("'Common Item'", "item_type", "VARCHAR(50)"));

        return DataxUtil.createProcedureCode(tempTablePrimaryKeyFieldName, tempTableName, targetTableName,
                fieldList, "order_source");
    }

}
